package wyx240407;

import java.math.*;

public class Day02 {
    BigDecimal a;
    BigDecimal b;
    char c;
    public Day02() {
        a=new BigDecimal("0");
        b=new BigDecimal("0");
        c='+';
    }

    public Day02(BigDecimal a, BigDecimal b, char c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public BigDecimal getA() {
        return a;
    }

    public void setA(BigDecimal a) {
        this.a = a;
    }

    public void setB(BigDecimal b) {
        this.b = b;
    }

    public void setC(char c) {
        this.c = c;
    }

    public BigDecimal compute() {
        BigDecimal result = new BigDecimal("0");
        switch (c) {
            case '+':
                result =a.add(b);
                break;
            case '-':
                result = a.subtract(b);
                break;
            case '*':
                result = a.multiply(b);
                break;
            case '/':
                result = a.divide(b,2,RoundingMode.HALF_UP);
                break;
            case '%':
                result = new BigDecimal(a.toBigInteger().mod(b.toBigInteger()));
                break;
            case '^':
                result = a.pow(b.intValue());
                break;
            default:
                break;
        }
        return result;
    }
}
